package io;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class Copy {
	private static final int BUF_SIZE = 256 * 1024 - 1;

	public static void main(String[] args) {
		try {
			long start = System.currentTimeMillis();
			DataInputStream dis = new DataInputStream(new FileInputStream(
					new File("data/data.bin")));
			DataOutputStream dos = new DataOutputStream(new FileOutputStream(
					new File("data/out.bin")));
			byte[] buf = new byte[BUF_SIZE];
			int size = BUF_SIZE + 1;
			while (size > 0) {
				size = dis.read(buf);
				if (size > 0) {
					dos.write(buf, 0, size);
				}
			}
			dis.close();
			dos.close();
			long end = System.currentTimeMillis();
			long delta = end - start;
			System.out.println("Total time (local copy): " + delta + " ms.");
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
